package com.dxc.intern.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dxc.intern.entity.QrCode;
import com.dxc.intern.mapper.QrCodeMapper;
import com.dxc.intern.service.QrCodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 二维码(求职者扫码操作) 服务实现类
 * </p>
 *
 * @author zhangchengming
 * @since 2022-02-21
 */
@Service
public class QrCodeServiceImpl extends ServiceImpl<QrCodeMapper, QrCode> implements QrCodeService {

    @Autowired
    QrCodeMapper qrCodeMapper;

    @Override
    public int getcount() {
        return qrCodeMapper.getcount();
    }

    @Override
    public void addQrCode(QrCode qrCode) {
        qrCodeMapper.insert(qrCode);
    }

    @Override
    public QrCode getlast() {
        return qrCodeMapper.getlast();
    }

    @Override
    public void delQrCode(Integer id) {
        qrCodeMapper.deleteById(id);
    }

    @Override
    public void updateQrCode(QrCode qrCode) {
        qrCodeMapper.updateById(qrCode);
    }

    @Override
    public IPage<QrCode> getQrCodeByNameOrStatus(Long current, Long size, QrCode qrCode) {
        QueryWrapper<QrCode> queryWrapper= new QueryWrapper<>();
        if(qrCode!=null){
            if(qrCode.getQrName()!=null){
                queryWrapper.like("qr_name",qrCode.getQrName());
            }
            if(qrCode.getQrStatus()!=null){
                queryWrapper.like("qr_status",qrCode.getQrStatus());
            }
        }
//        Map<String, Object> queryParamsMap = new HashMap<>();
//        queryParamsMap.put("qr_name", "%"+qrCode.getQrName()+"%");
//        queryParamsMap.put("qr_status", qrCode.getQrStatus());
//        queryWrapper.allEq(queryParamsMap,false);
        return qrCodeMapper.selectPage(new Page<QrCode>(current,size),queryWrapper);
    }

    @Override
    public Object getQrCodeById(Integer id) {
        return qrCodeMapper.selectById(id);
    }

    @Override
    public QrCode getQrCodeByurl(String url) {
        QueryWrapper<QrCode> queryWrapper= new QueryWrapper<>();
        queryWrapper.like("qr_addr",url);
        return qrCodeMapper.selectOne(queryWrapper);
    }
}
